﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using PPIDesktopClient.Entities;
using PPIDesktopClient.Logic;
using System.ComponentModel;

namespace PPIDesktopClient.General
{
    public class SaveAssetProcess : Process
    {
        EVendor_Visit_XMissionStructure m_Vendor_Visit_XMissionStructure;
        int m_TotalInformation;
        int m_UploadInformation;

        public SaveAssetProcess(EVendor_Visit_XMissionStructure structure)
        {
            m_Vendor_Visit_XMissionStructure = structure;
            CalculateteTotalData();
        }

        private void CalculateteTotalData()
        {
            m_TotalInformation = 1;
            m_TotalInformation += m_Vendor_Visit_XMissionStructure.Images.Count;
            m_TotalInformation += m_Vendor_Visit_XMissionStructure.Poles.Count;
        }

        public override void StartProcess()
        {
            if (!m_ProcessWorker.IsBusy)
            {
                m_ProcessWorker.RunWorkerAsync();
            }
        }

        protected override void Work()
        {
            LVendor_Visit_XMissionStructure _Logic = new LVendor_Visit_XMissionStructure();
            _Logic.SaveStructure += new EventHandler(_Logic_SaveStructure);
            _Logic.SavePole += new EventHandler(_Logic_SavePole);
            _Logic.SaveImage += new EventHandler(_Logic_SaveImage);
            _Logic.Save(m_Vendor_Visit_XMissionStructure);
        }

        #region Events

        void _Logic_SaveImage(object sender, EventArgs e)
        {
            m_UploadInformation++;
            OnSaveProgressChanged(sender, new ProgressChangedEventArgs(CalculateProgress(m_UploadInformation, m_TotalInformation), new object()));
        }

        void _Logic_SavePole(object sender, EventArgs e)
        {
            m_UploadInformation++;
            OnSaveProgressChanged(sender, new ProgressChangedEventArgs(CalculateProgress(m_UploadInformation, m_TotalInformation), new object()));
        }

        void _Logic_SaveStructure(object sender, EventArgs e)
        {
            m_UploadInformation++;
            OnSaveProgressChanged(sender, new ProgressChangedEventArgs(CalculateProgress(m_UploadInformation,m_TotalInformation), new object()));
        }

        #endregion
    }
}
